<?php

	class VegetCategoryService{
		static $CATEGORY_ROOT_ID =  221;
		private $db;
		
		function VegetCategoryService($db = NULL){
			if($db){
				$this->db = $db;
			}
			
			if (!$this->db){
				require_once 'plugins/db.php';
				$this->db = new Db();
			}
		}
		
		function getIndexCategoryList(){
			$firstFloorCateList = $this->getCategoryListByParentId(self::$CATEGORY_ROOT_ID, 5);
			
			foreach ($firstFloorCateList as $k=>$v){
				$firstFloorCateList[$k]['child'] = $this->getCategoryListByParentId($v['id'], 20);
			}
			
			return $firstFloorCateList;
		}
		
		function getCategoryListByParentId($parentId = 0, $limit = -1){
			/*
			if(!$parentId){
				return false;
			}*/
			
			$sql = "select * from dragon_fancai_category where parent_id=".addslashes($parentId);
			if($limit > 0){
				$sql .= " limit ".addslashes($limit);
			}
						
			return $this->db->fetchRows($sql);
		}
		
		
		
		
	}


?>